﻿
// written by Tim Fischer, 2008
// All items beginning with an "TF.X" are from the www.cross-browser.com library
// *** --> This library *WILL* cause IE to have massive memory leaks while debugging in VS 2005/2008.
// *** --> It will not leak while running IE without debugging.
// #pragma NoCompStart
/*
tfcore.js  2.0a
All events/shared functions for javascript
*/
// #pragma NoCompEnd

//'NameSpaces' defined
_TF = top;
TF = document;
TF.mEvents = TF.mEvents || {};
if (typeof _TF.Controls === "undefined") { _TF.Controls = {}; }
if (typeof _TF.Cookie === "undefined") { _TF.Cookie = {}; }
if (typeof _TF.Element === "undefined") { _TF.Element = {}; }
if (typeof _TF.String === "undefined") { _TF.String = {}; }
if (typeof _TF.Util === "undefined") { _TF.Util = {}; }
TF.X = TF.X || {};

window._onDOMLoadEvents = [];
window._DOMContentLoadedInitDone = false;

_TF.String.toBoolean=function(inputString) { if (typeof (inputString) == "string") { inputString = inputString.toLowerCase(); } switch (inputString) { case "1": case "true": case "yes": case "y": case 1: case true: return true; default: return false; } }
_TF.String.ltrim = function(str, chars) {
    chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
};

_TF.String.rtrim = function(str, chars) {
    chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
};

_TF.String.trim = function(str, chars) {
    return ltrim(rtrim(str, chars), chars);
};

_TF.is = { ie: navigator.appName == 'Microsoft Internet Explorer', java: navigator.javaEnabled(), ns: navigator.appName == 'Netscape', ua: navigator.userAgent.toLowerCase(), version: parseFloat(navigator.appVersion.substr(21)) || parseFloat(navigator.appVersion), win: navigator.platform == 'Win32' };
_TF.is.mac = _TF.is.ua.indexOf('mac') >= 0; _TF.is.ff = _TF.is.ua.indexOf('firefox') >= 0; if (_TF.is.ua.indexOf('opera') >= 0) { _TF.is.ie = _TF.is.ns = false; _TF.is.opera = true; }
if (_TF.is.ua.indexOf('gecko') >= 0) { _TF.is.ie = _TF.is.ns = false; _TF.is.gecko = true; }

//cross-browser.com functions
TF.X.GetElementById = function(e) { if (typeof (e) == 'string') { if (document.getElementById) e = document.getElementById(e); else if (document.all) e = document.all[e]; else e = null; } return e; };
TF.X.GetElementsByTagName = function(t, p) {
    ///<summary>Gets an array of all elements of a specific tag...</summary>
    ///<param name="t"> tag (DIV, TABLE, TD, etc)</param>
    ///<param name="p"> Element id to start search at</param>
    ///<returns>Array of elements</returns>
    var list = null;
    t = t || '*';
    p = _gE(p) || document;
    if (typeof p.getElementsByTagName != 'undefined') { // DOM1
        list = p.getElementsByTagName(t);
        if (t == '*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
    }
    else { // IE4 object model
        if (t == '*') list = p.all;
        else if (p.all && p.all.tags) list = p.all.tags(t);
    }
    return list || [];
};

TF.X.GetElementsByClassName = function(cName, pEle, tagName, fnCall) {
    ///<summary>Gets an array of all elements using a specific CSS Class.</summary>
    ///<param name="cName"> tag (DIV, TABLE, TD, etc)</param>
    ///<param name="pEle"> Element id to start search at</param>
    ///<param name="tagName"> Element id to start search at</param>
    ///<param name="fnCall">Callback function, iterates thru the returned list. Is passed a reference to each Element object found</param>
    ///<returns>Array of elements</returns>
    var r = [];
    var re = new RegExp("(^|\\s)" + cName + "(\\s|$)");
    var e = TF.X.GetElementsByTagName(tagName, pEle); //pEle.getElementsByTagName(tagName);
    for (var i = 0; i < e.length; ++i) {
        if (re.test(e[i].className)) {
            r[r.length] = e[i];
            if (fnCall) { fnCall(e[i]); }
        }
    }
    return r;
};

TF.X.ClientHeight = function() {
    ///<summary>The inner height of the window not including any scrollbar.</summary>
    ///<returns>Integer</returns>
    var v = 0, d = document, w = window;
    if ((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
    { v = d.documentElement.clientHeight; }
    else if (d.body && d.body.clientHeight)
    { v = d.body.clientHeight; }
    else if (TF.X.Def(w.innerWidth, w.innerHeight, d.width)) {
        v = w.innerHeight;
        if (d.width > w.innerWidth) v -= 16;
    }
    return v;
};

TF.X.ClientWidth = function() {
    ///<summary>The inner height of the window not including any scrollbar.</summary>
    ///<returns>Integer</returns>
    var v = 0, d = document, w = window;
    if ((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
    { v = d.documentElement.clientWidth; }
    else if (d.body && d.body.clientWidth)
    { v = d.body.clientWidth; }
    else if (TF.X.Def(w.innerWidth, w.innerHeight, d.height)) {
        v = w.innerWidth;
        if (d.height > w.innerHeight) v -= 16;
    }
    return v;
};

TF.X.Event = function(evt) { var e = evt || window.event; if (!e) { return; } this.type = e.type; this.target = e.target || e.srcElement; this.relatedTarget = e.relatedTarget; if (TF.X.Def(e.pageX)) { this.pageX = e.pageX; this.pageY = e.pageY; } else if (TF.X.Def(e.clientX)) { this.pageX = e.clientX + TF.X.ScrollLeft(); this.pageY = e.clientY + TF.X.ScrollTop(); } if (TF.X.Def(e.offsetX)) { this.offsetX = e.offsetX; this.offsetY = e.offsetY; } else if (TF.X.Def(e.layerX)) { this.offsetX = e.layerX; this.offsetY = e.layerY; } else { this.offsetX = this.pageX - TF.X.PageX(this.target); this.offsetY = this.pageY - TF.X.PageY(this.target); } this.keyCode = e.keyCode || e.which || 0; this.shiftKey = e.shiftKey; this.ctrlKey = e.ctrlKey; this.altKey = e.altKey; if (typeof e.type == 'string') { if (e.type.indexOf('click') != -1) { this.button = 0; } else if (e.type.indexOf('mouse') != -1) { this.button = e.button; } } };
TF.X.PreventDefault = function(e) { if (e && e.preventDefault) { e.preventDefault(); } else if (window.event) { window.event.returnValue = false; } };
TF.X.HasPoint = function(e, x, y, t, r, b, l) { if (!TF.X.Num(t)) { t = r = b = l = 0; } else if (!TF.X.Num(r)) { r = b = l = t; } else if (!TF.X.Num(b)) { l = r; b = t; } var eX = TF.X.PageX(e), eY = TF.X.PageY(e); return (x >= eX + l && x <= eX + TF.X.Width(e) - r && y >= eY + t && y <= eY + TF.X.Height(e) - b); }
TF.X.Height = function(e, h) {
    ///<summary>Return and optionally set the element's height. It attempts to return and/or set the equivalent of 'offsetHeight'.</summary>
    ///<param name="e"> id string or object reference</param>
    ///<param name="h"> unsigned integer height; it is rounded to an integer</param>
    ///<returns>Integer</returns>
    if (!(e = _gE(e))) return 0; if (TF.X.Num(h)) { if (h < 0) h = 0; else h = Math.round(h); } else h = -1; var css = TF.X.Def(e.style); if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') { h = TF.X.ClientHeight(); } else if (css && TF.X.Def(e.offsetHeight) && TF.X.Str(e.style.height)) { if (h >= 0) { var pt = 0, pb = 0, bt = 0, bb = 0; if (document.compatMode == 'CSS1Compat') { var gcs = TF.X.GetComputedStyle; pt = gcs(e, 'padding-top', 1); if (pt !== null) { pb = gcs(e, 'padding-bottom', 1); bt = gcs(e, 'border-top-width', 1); bb = gcs(e, 'border-bottom-width', 1); } else if (TF.X.Def(e.offsetHeight, e.style.height)) { e.style.height = h + 'px'; pt = e.offsetHeight - h; } } h -= (pt + pb + bt + bb); if (isNaN(h) || h < 0) return; else e.style.height = h + 'px'; } h = e.offsetHeight; } else if (css && TF.X.Def(e.style.pixelHeight)) { if (h >= 0) e.style.pixelHeight = h; h = e.style.pixelHeight; } return h;
};

TF.X.Left = function(e, iX) {
    if (!(e = _gE(e))) return 0; var css = TF.X.Def(e.style); if (css && TF.X.Str(e.style.left)) {
        if (TF.X.Num(iX)) e.style.left = iX + 'px'; else
        { iX = parseInt(e.style.left); if (isNaN(iX)) iX = TF.X.GetComputedStyle(e, 'left', 1); if (isNaN(iX)) iX = 0; }
    } else if (css && TF.X.Def(e.style.pixelLeft)) { if (TF.X.Num(iX)) e.style.pixelLeft = iX; else iX = e.style.pixelLeft; } return iX;
};
TF.X.MoveTo = function(e, x, y) { TF.X.Left(e, x); TF.X.Top(e, y); };
TF.X.Num = function() { for (var i = 0; i < arguments.length; ++i) { if (isNaN(arguments[i]) || typeof (arguments[i]) != 'number') return false; } return true; };
TF.X.Opacity = function(e, o) { var iset = TF.X.Def(o); if (!(e = _gE(e))) return 2; if (TF.X.Str(e.style.opacity)) { if (iset) e.style.opacity = o + ''; else o = parseFloat(e.style.opacity); } else if (TF.X.Str(e.style.filter)) { if (iset) e.style.filter = 'alpha(opacity=' + (100 * o) + ')'; else if (e.filters && e.filters.alpha) { o = e.filters.alpha.opacity / 100; } } else if (TF.X.Str(e.style.MozOpacity)) { if (iset) e.style.MozOpacity = o + ''; else o = parseFloat(e.style.MozOpacity); } else if (TF.X.Str(e.style.KhtmlOpacity)) { if (iset) e.style.KhtmlOpacity = o + ''; else o = parseFloat(e.style.KhtmlOpacity); } return isNaN(o) ? 1 : o; };
TF.X.PageX = function(e) { var x = 0; e = _gE(e); while (e) { if (TF.X.Def(e.offsetLeft)) x += e.offsetLeft; e = TF.X.Def(e.offsetParent) ? e.offsetParent : null; } return x; };
TF.X.PageY = function(e) { var y = 0; e = _gE(e); while (e) { if (TF.X.Def(e.offsetTop)) y += e.offsetTop; e = TF.X.Def(e.offsetParent) ? e.offsetParent : null; } return y; };
TF.X.ResizeTo = function(e, w, h) { TF.X.Width(e, w); TF.X.Height(e, h); };
TF.X.Str = function(s) {
    ///<summary>Determine if all arguments are of type 'string'.</summary>
    ///<param name="s">ref[, etc]</param>
    ///<returns>true if all its arguments are string</returns>
    for (var i = 0; i < arguments.length; ++i) { if (typeof (arguments[i]) != 'string') return false; } return true;
};

TF.X.Style = function(sProp, sVal) {
    var i, e; for (i = 2; i < arguments.length; ++i) {
        e = _gE(arguments[i]); if (e.style) {
            try { e.style[sProp] = sVal; } catch (err) { e.style[sProp] = ''; }
        }
    }
};
TF.X.Top = function(e, iY) {
    if (!(e = _gE(e))) return 0; var css = TF.X.Def(e.style); if (css && TF.X.Str(e.style.top)) {
        if (TF.X.Num(iY)) e.style.top = iY + 'px'; else
        { iY = parseInt(e.style.top); if (isNaN(iY)) iY = TF.X.GetComputedStyle(e, 'top', 1); if (isNaN(iY)) iY = 0; }
    } else if (css && TF.X.Def(e.style.pixelTop)) { if (TF.X.Num(iY)) e.style.pixelTop = iY; else iY = e.style.pixelTop; } return iY;
};

TF.X.Width = function(e, w) { if (!(e = _gE(e))) return 0; if (TF.X.Num(w)) { if (w < 0) w = 0; else w = Math.round(w); } else w = -1; var css = TF.X.Def(e.style); if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') { w = TF.X.ClientWidth(); } else if (css && TF.X.Def(e.offsetWidth) && TF.X.Str(e.style.width)) { if (w >= 0) { var pl = 0, pr = 0, bl = 0, br = 0; if (document.compatMode == 'CSS1Compat') { var gcs = TF.X.GetComputedStyle; pl = gcs(e, 'padding-left', 1); if (pl !== null) { pr = gcs(e, 'padding-right', 1); bl = gcs(e, 'border-left-width', 1); br = gcs(e, 'border-right-width', 1); } else if (TF.X.Def(e.offsetWidth, e.style.width)) { e.style.width = w + 'px'; pl = e.offsetWidth - w; } } w -= (pl + pr + bl + br); if (isNaN(w) || w < 0) return; else e.style.width = w + 'px'; } w = e.offsetWidth; } else if (css && TF.X.Def(e.style.pixelWidth)) { if (w >= 0) e.style.pixelWidth = w; w = e.style.pixelWidth; } return w; };
TF.X.NextSib = function(e, t) { e = _gE(e); var s = e ? e.nextSibling : null; while (s) { if (s.nodeType == 1 && (!t || s.nodeName.toLowerCase() == t.toLowerCase())) { break; } s = s.nextSibling; } return s; };
TF.X.FirstChild = function(e, t) { e = _gE(e); var c = e ? e.firstChild : null; while (c) { if (c.nodeType == 1 && (!t || c.nodeName.toLowerCase() == t.toLowerCase())) { break; } c = c.nextSibling; } return c; };

getViewPortHeight = function() { var v = 0, d = document, w = window; if ((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight) { v = d.documentElement.clientHeight; } else if (d.body && d.body.clientHeight) { v = d.body.clientHeight; } else if (TF.X.Def(w.innerWidth, w.innerHeight, d.width)) { v = w.innerHeight; if (d.width > w.innerWidth) v -= 16; } return v; };
getViewPortWidth = function() { var v = 0, d = document, w = window; if ((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth) { v = d.documentElement.clientWidth; } else if (d.body && d.body.clientWidth) { v = d.body.clientWidth; } else if (TF.X.Def(w.innerWidth, w.innerHeight, d.height)) { v = w.innerWidth; if (d.height > w.innerHeight) v -= 16; } return v; };

TF.X.Def = function() { for (var i = 0; i < arguments.length; ++i) { if (typeof (arguments[i]) == 'undefined') return false; } return true; };
TF.X.Camelize = function(cssPropStr) { var i, c, a = cssPropStr.split('-'); var s = a[0]; for (i = 1; i < a.length; ++i) { c = a[i].charAt(0); s += a[i].replace(c, c.toUpperCase()); } return s; };
TF.X.GetComputedStyle = function(e, p, i) { if (!(e = _gE(e))) return null; var s, v = 'undefined', dv = document.defaultView; if (dv && dv.getComputedStyle) { s = dv.getComputedStyle(e, ''); if (s) v = s.getPropertyValue(p); } else if (e.currentStyle) { v = e.currentStyle[TF.X.Camelize(p)]; } else return null; return i ? (parseInt(v) || 0) : v; };

TF.X.ScrollLeft = function(e, bWin) { var offset = 0; if (!TF.X.Def(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') { var w = window; if (bWin && e) w = e; if (w.document.documentElement && w.document.documentElement.scrollLeft) offset = w.document.documentElement.scrollLeft; else if (w.document.body && TF.X.Def(w.document.body.scrollLeft)) offset = w.document.body.scrollLeft; } else { e = _gE(e); if (e && TF.X.Num(e.scrollLeft)) offset = e.scrollLeft; } return offset; };
TF.X.ScrollTop = function(e, bWin) { var offset = 0; if (!TF.X.Def(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') { var w = window; if (bWin && e) w = e; if (w.document.documentElement && w.document.documentElement.scrollTop) offset = w.document.documentElement.scrollTop; else if (w.document.body && TF.X.Def(w.document.body.scrollTop)) offset = w.document.body.scrollTop; } else { e = _gE(e); if (e && TF.X.Num(e.scrollTop)) offset = e.scrollTop; } return offset; };
TF.X.OffsetLeft = function(e) {
    if (!(e = TF.X.GetElementById(e))) return 0;
    if (TF.X.Def(e.offsetLeft)) return e.offsetLeft;
    else return 0;
};
TF.X.OffsetTop = function(e) {
    if (!(e = TF.X.GetElementById(e))) return 0;
    if (TF.X.Def(e.offsetTop)) return e.offsetTop;
    else return 0;
};

_TF.Util.addTooltip = function(elemID, text, context) {
    _gE(elemID).title = text;
    $('#' + elemID).cluetip({
        splitTitle: '|',
        leftOffset: 25,
        cluetipClass: 'jtip',
        dropShadow: true,
        arrows: true,
        showTitle: false
    });
};


// Helpers
_gE = function(o) {
    ///<summary>Helper function to call TF.X.GetElementById</summary>
    ///<param name="o">ID of element for TF.X.GetElementById</param>
    ///<returns>element</returns>
    return TF.X.GetElementById(o);
};


FixEvent = function(event) {
    ///<summary> add W3C standard event methods</summary>
    event.preventDefault = FixEvent.preventDefault;
    event.stopPropagation = FixEvent.stopPropagation;
    return event;
};
FixEvent.preventDefault = function() {
    this.returnValue = false;
};
FixEvent.stopPropagation = function() {
    this.cancelBubble = true;
};

ReleaseEvents = function(el) {
    var EnumEvents = ["focus", "blur", "change", "click", "mousedown",
                  "mouseup", "mouseover", "keypress", "keydown",
                  "keyup", "keypress"];

    var helper = function(obj) {
        var i;
        for (i = 0; i < EnumEvents.length; i++) {
            obj["on" + EnumEvents[i]] = null;
        }
        for (i = 0; i < parent.childNodes.length; i++) {
            helper(parent.childNodes[i]);
        }
    };
    helper(el);
};

_RemoveEvent = function(element, type, handler) {
    if (element.removeEventListener) {
        element.removeEventListener(type, handler, false);
    } else {
        // delete the event handler from the hash table
        if (element.events && element.events[type]) {
            delete element.events[type][handler.$$guid];
        }
    }
};

//function edHandleEvent(event) {
//    var returnValue = true;
//    // grab the event object (IE uses a global event object)
//    event = event || edFixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
//    // get a reference to the hash table of event handlers
//    var handlers = this.events[event.type];
//    for (var i in handlers) {
//        this.$$edHandleEvent = handlers[i];
//        if (this.$$edHandleEvent(event) == false) { returnValue = false; }
//    }
//    return returnValue;
//}

function TFHandleEvent(event) {
    var returnValue = true;
    // grab the event object (IE uses a global event object)
    event = event || FixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
    // get a reference to the hash table of event handlers
    var handlers = this.events[event.type];
    for (var i in handlers) {
        this.$$TFHandleEvent = handlers[i];
        if (this.$$TFHandleEvent(event) == false) { returnValue = false; }
    }
    return returnValue;
};

// Function that adds DOMContentLoaded listeners to the array.
_addDOMLoadEvent = function(listener) {
    // If the DOMContentLoaded event has happened, run the function.
    if (window._DOMContentLoadedInitDone) { listener(); return; }
    _onDOMLoadEvents[window._onDOMLoadEvents.length] = listener;
};

// Dean Edwards AddEvent - obliterates memory leaks in ie due to event handling
_AddEvent = function(element, type, handler) {
    if (type == "DOMContentLoaded" || type == "domload") { _addDOMLoadEvent(handler); return; }

    if (element.addEventListener) {
        element.addEventListener(type, handler, false);
    } else {
        // assign each event handler a unique ID
        if (!handler.$$guid) {
            handler.$$guid = _AddEvent.guid++;
        }
        // create a hash table of event types for the element
        if (!element.events) {
            element.events = {};
        }
        // create a hash table of event handlers for each element/event pair
        var handlers = element.events[type];
        if (!handlers) {
            handlers = element.events[type] = {};
            // store the existing event handler (if there is one)
            if (element["on" + type]) {
                handlers[0] = element["on" + type];
            }
        }
        // store the event handler in the hash table
        handlers[handler.$$guid] = handler;
        // assign a global event handler to do all the work
        element["on" + type] = TFHandleEvent;
    }
};
// a counter used to create unique IDs
_AddEvent.guid = 1;
// End Dean Edwards addEvent.


String.prototype.replaceAll=function(strTarget, strSubString){
  var strText = this;
  var intIndexOfMatch=strText.indexOf(strTarget);
  while(intIndexOfMatch !=-1){
   strText = strText.replace(strTarget,strSubString);
   intIndexOfMatch = strText.indexOf(strTarget);
  }
  return strText;
};

//String.prototype.replaceChar = function(s, c, n) {
//    (s = s.split(''))[--n] = c; return s.join('');
//};


_TF.Util.getUrlParam = function(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); if (results == null) return ""; else return results[1];
};

_TF.Util.CloneArray = function(_Arr) {
    var array = []; var iter = _Arr.length; if (iter > 3) {
        var tVal = 0; var n = iter % 4; if (n > 0) {
            do
            { array[tVal] = _Arr[tVal]; tVal++; } while (--n);
        } n = parseInt(iter / 4); do
        { array[tVal] = _Arr[tVal]; tVal++; array[tVal] = _Arr[tVal]; tVal++; array[tVal] = _Arr[tVal]; tVal++; array[tVal] = _Arr[tVal]; tVal++; } while (--n);
    } else
    { for (var nX in _Arr) { array[nX] = _Arr[nX]; } } return array;
};


_TF.Element.really_over = function(src) {
    if (!_TF.is.ie || !window.event) { return true; }
    var event = window.event;
    var from = event.fromElement;
    var to = event.toElement;
    
    return (to == src || src.contains(to)) && !src.contains(from) && src != from;
};
_TF.Element.really_out = function(src) {
if (!_TF.is.ie || !window.event) { return true; }
    var event = window.event;
    var from = event.fromElement;
    var to = event.toElement;
    return (src == from || src.contains(from)) && !src.contains(to) && src != to;
};


_TF.Element.isElementInside = function(src, dest) {
    while (src != null) { if (src.id == dest.id) { return true; } src = src.parentNode; }
    return false;
};


_TF.Element.SafelyRemoveNode = function(node, andSelf) {
    ///<summary>Removes DOM Nodes and their repsective events properly to ensure no memory leaks</summary>
    ///<param name="node">DOM element</param>
    ///<param name="andSelf">set to true to remove the DOM element or false to only remove it's children</param>
    ///<returns>none</returns>
if (node == undefined || node == null) { return; }
    while (node.hasChildNodes()) {
        if (node.lastChild.nodeName == 'IFRAME') {
            node.lastChild.src = "javascript:false;";
        }
        _TF.Element.SafelyRemoveNode(node.lastChild);
    }
    if (node.events != undefined) { node.events = null; }
    if (node.innerText) { node.innerText = ''; }
    if (andSelf != false) { node.parentNode.removeChild(node); }
};

var Drag = {

    obj: null,

    init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
        o.onmousedown = Drag.start;

        o.hmode = bSwapHorzRef ? false : true;
        o.vmode = bSwapVertRef ? false : true;

        o.root = oRoot && oRoot != null ? oRoot : o;

        if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
        if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX = typeof minX != 'undefined' ? minX : null;
        o.minY = typeof minY != 'undefined' ? minY : null;
        o.maxX = typeof maxX != 'undefined' ? maxX : null;
        o.maxY = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart = new Function();
        o.root.onDragEnd = new Function();
        o.root.onDrag = new Function();
    },

    start: function(e) {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        o.root.onDragStart(x, y);

        o.lastMouseX = e.clientX;
        o.lastMouseY = e.clientY;

        if (o.hmode) {
            if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
            if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
            if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove = Drag.drag;
        document.onmouseup = Drag.end;

        return false;
    },

    drag: function(e) {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey = e.clientY;
        var ex = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper) nx = o.xMapper(y)
        else if (o.yMapper) ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX = ex;
        Drag.obj.lastMouseY = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end: function() {
        document.onmousemove = null;
        document.onmouseup = null;
        Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE: function(e) {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};

_TF.Element.EnableDrag = function(id, fS, fD, fE, bEnabled) {

    var mx = 0, my = 0;
    if (typeof id == Object) { this.el = id; }
    else { this.el = _gE(id); }

    function dragStart(e) {
        if (this.el.DragEnabled) {
            var ev = new TF.X.Event(e);
            TF.X.PreventDefault(e);
            mx = ev.pageX;
            my = ev.pageY;
            _AddEvent(window, 'mousemove', drag, false);
            _AddEvent(window, 'mouseup', dragEnd, false);
            if (fS) { fS(el, ev.pageX, ev.pageY, ev); }
        }
    }

    function drag(e) {
        var ev, dx, dy;
        TF.X.PreventDefault(e);
        ev = new TF.X.Event(e);
        dx = ev.pageX - mx;
        dy = ev.pageY - my;
        mx = ev.pageX;
        my = ev.pageY;
        if (fD) { fD(this.el, dx, dy, ev); }
        else { TF.X.MoveTo(this.el, TF.X.Left(this.el) + dx, TF.X.Top(this.el) + dy); }
    }

    function dragEnd(e) {
        var ev = new TF.X.Event(e);
        TF.X.PreventDefault(e);
        _RemoveEvent(document, 'mouseup', dragEnd);
        _RemoveEvent(document, 'mousemove', drag);
        if (fE) { fE(this.el, ev.pageX, ev.pageY, ev); }
        if (_TF.Element.EnableDrag.drop) { _TF.Element.EnableDrag.drop(this.el, ev); }
    }

    if (this.el) {
        if (bEnabled == false) {
            this.el.DragEnabled = false;
            _RemoveEvent(this.el, 'mousedown', dragStart);
        }
        else {
            this.el.DragEnabled = true;
            _AddEvent(this.el, 'mousedown', dragStart, false);
        }
    }
};
_TF.Element.EnableDrag.drops = [];


if (_TF.Cookie["setCookie"] == null) {
    _TF.Cookie.setCookie = function(name, value, expire, path) {
        ///<summary>Creates a cookie on the client machine</summary>
        ///<param name="name">Name of the cookie to create</param>
        ///<param name="value">what to store in the cookie</param>
        ///<param name="expire">when to expire</param>
        ///<param name="path">Path of the cookie to create</param>
        ///<returns>None.</returns>      
        document.cookie = name + "=" + escape(value) +
                ((!expire) ? "" : ("; expires=" + expire.toGMTString())) +
                "; path=" + ((!path) ? "/" : path);
        return null;
    };

    _TF.Cookie.getCookie = function(name) {
        ///<summary>Gets a previously saved cookie</summary>
        ///<param name="name">Name of the cookie to retrieve</param>
        ///<returns>contents of the cookie</returns>    
        var value = null, search = name + "=";
        if (document.cookie.length > 0) {
            var offset = document.cookie.indexOf(search);
            if (offset != -1) {
                offset += search.length;
                var end = document.cookie.indexOf(";", offset);
                if (end == -1) end = document.cookie.length;
                value = unescape(document.cookie.substring(offset, end));
            }
        }
        return value;
    };  // end of getCookie function

    _TF.Cookie.deleteCookie = function(name, path) {
        ///<summary>Deletes a previously saved cookie</summary>
        ///<param name="name">Name of the cookie to retrieve</param>
        ///<param name="path">Path of the cookie to delete</param>
        ///<returns>None.</returns>  
        if (_TF.U.getCookie(name)) {
            document.cookie = name + "=" +
                "; path=" + ((!path) ? "/" : path) +
                "; expires=" + new Date(0).toGMTString();
        }
    };
} // end _TF.Cookie

if (_TF.Util["getXMLHTTP"] == null) {
    _TF.Util.getXMLHTTP = function() {
        ///<summary>gets an XMLHTTP object for server side callbacks</summary>
        ///<returns>xmlhttp object</returns>  
        var xmlhttp = false;
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            try
            { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }
        } if (!xmlhttp && window.createRequest) {
            try
            { xmlhttp = window.createRequest(); } catch (e2) { xmlhttp = false; }
        } if (!xmlhttp) {
            try
            { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e3) { xmlhttp = false; }
        } return xmlhttp;
    };

    _TF.Util.addTooltip = function(elemID, text) {
        _gE(elemID).title = text;
        $('#'+elemID).cluetip({
            cluetipClass: 'jtip',
            arrows: true,
            dropShadow: false,
            hoverIntent: false,
            sticky: true,
            mouseOutClose: true,
            closePosition: 'title',
            closeText: '<img src="cross.png" alt="close" />'
        });
    }
    
    _TF.Util.addTooltip1 = function(elem, text) {
        ///<summary>Creates a tooltip to hover over any element</summary>
        ///<param name="elem">Element to create the tooltip for (hover over)</param>
        ///<param name="text">The text inside the tooltip</param>
        ///<returns>Tooltip Object.</returns>  

        _me = this;
        _me.txt = text;

        _me.showToolTip = function(event) {
            if (document.all) this.e = event;
            var r = '';
            var y = this.e.clientY;
            if (y < 55) {
                r = 'r';
            }
            this.obj = _gE('edtooltip');

            if (this.obj == null) {
                this.obj = document.createElement('div');
                this.obj.id = 'edtooltip';

                this.objTop = document.createElement('div');
                this.objTop.appendChild(document.createElement('span'));

                this.objMid = document.createElement('div');
                this.objMid.className = 'edmiddle';

                this.obj2 = document.createElement('span');
                this.obj2.id = 'edtooltip_content';

                this.objMid.appendChild(this.obj2);
                this.objBtm = document.createElement('div');

                this.obj.appendChild(this.objTop);
                this.obj.appendChild(this.objMid);
                this.obj.appendChild(this.objBtm);
                document.body.appendChild(this.obj);
            }
            else {
                this.obj2 = _gE('edtooltip_content');
            }

            this.obj2.innerHTML = _me.txt;
            this.obj.style.display = 'block';
            var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
            if (is.mac) { st = 0; }
            var leftPos = this.e.clientX - 100;
            if (leftPos < 0) leftPos = 0;
            this.obj.style.left = leftPos + 'px';
            if (r == 'r') {
                this.objTop.className = 'edtopr';
                this.objBtm.className = 'edbottomr';
                this.obj.style.top = y + 16 + st + 'px';
            }
            else {
                this.objTop.className = 'edtop';
                this.objBtm.className = 'edbottom';
                this.obj.style.top = y - this.obj.offsetHeight - 1 + st + 'px';
            }
        }

        _me.hideToolTip = function() {
            _gE('edtooltip').style.display = 'none';
        }

        _AddEvent(_gE(elem), "mousemove", this.showToolTip);
        _AddEvent(_gE(elem), "mouseout", this.hideToolTip);
    };

    _TF.Util.HTMLEncode = function(strHTML) {
        ///<summary>Encode HTML to pass via Javascript in code behind</summary>
        ///<param name="strHTML">HTML to encode to ensure all quotes are escaped, etc.</param>
        ///<returns>Encoded HTML</returns>
        var div = document.createElement('div');
        div.innerText = strHTML;
        return div.innerHTML;
    };

    _TF.Util.HTMLDecode = function(strEncodeHTML) {
        ///<summary>Decode HTML to fix escaped characters so they display properly</summary>
        ///<param name="strEncodeHTML">HTML to encode to ensure all quotes are escaped, etc.</param>
        ///<returns>Encoded HTML</returns>
        var div = document.createElement('div');
        div.innerHTML = strEncodeHTML;
        return div.innerText;
    };


} // end of TF Object

// The Magic of Asynchronous JS (Sortof)
callWithSetTimeout = function(funcRef, a, b, c, d, e, f, g) {
    return function() { funcRef(a, b, c, d, e, f, g); };
};

_TF.DestroyObject = function(obj) {
    if (typeof obj !== "undefined") {
        window.setTimeout(function() { obj = null; alert(1); CollectGarbage(); }, 1000);
    }
};

_RaiseEvent = function(controlID, func, arg1, arg2, arg3, arg4) {
    var fName = window[controlID + "_" + func];
    if (typeof fName == 'function') {
        document[fName(arg1, arg2, arg3, arg4)];
    }
    else {
        fName = frames['ifMainContent'].window[controlID + "_" + func];
        if (typeof fName == 'function') {
            document[fName(arg1, arg2, arg3, arg4)];
        }
    }
};


_TF.Controls.Collapsible = function(ele, showAll) {
    this.showAll = showAll;

    this.iconOnClick = function() {
        var section = this.collapsibleSection;
        if (section.style.display != 'block') {
            section.style.display = 'block';
            this.className = 'CollapseIcon';
            this.title = 'Click to collapse';
        }
        else {
            section.style.display = 'none';
            this.className = 'ExpandIcon';
            this.title = 'Click to expand';
        }
    };

    this.iconOnMouseover = function() {
        this.collapsibleSection.style.backgroundColor = '#999999';
    };

    this.iconOnMouseout = function() {
        this.collapsibleSection.style.backgroundColor = 'transparent';
    };

    this.init = function() {
        var i, icon;
        headings = TF.X.GetElementsByClassName('collapsible', document, 'h2');
        for (i = 0; i < headings.length; i++) {
            icon = document.createElement('div');
            icon.collapsibleSection = TF.X.NextSib(headings[i]);
            _AddEvent(icon, "click", this.iconOnClick);
            //icon.onclick = iconOnClick;
            icon.onclick();
            if (showAll != true) {
                if (i > 0) icon.onclick();
            }
            _AddEvent(icon, "mouseover", this.iconOnMouseover);
            _AddEvent(icon, "mouseout", this.iconOnMouseout);
            //icon.onmouseover = iconOnMouseover;
            //icon.onmouseout = iconOnMouseout;
            headings[i].appendChild(icon);
        }
    };

};

_TF.Controls.setCBByText = function(elId, strDefault) {
    ///<summary>Set a DropDown or Listbox selection by it's Text.</summary>
    ///<param name="elId">The element ID of the listbox/combo/dropdown.</param>
    ///<param name="strDefault">The string to find in the listbox/combo/dropdown.</param>
    ///<returns>None.</returns>
    var sel = TF.X.GetElementById(elId);
    for (var i = 0; i < sel.options.length; i++) {
        if (sel.options[i].text == strDefault) { sel.selectedIndex = i; }
    }
};

_TF.Controls.setCBByValue = function(elemId, strDefault) {
    ///<summary>Set a DropDown or Listbox selection by it's Value.</summary>
    ///<param name="elId">The element ID of the listbox/combo/dropdown.</param>
    ///<param name="strDefault">The string to find in the listbox/combo/dropdown.</param>
    ///<returns>None.</returns>
    var sel = TF.X.GetElementById(elemId);
    for (var i = 0; i < sel.options.length; i++) {
        if (sel.options[i].value == strDefault) { sel.selectedIndex = i; }
    }
};

_TF.Controls.doClick = function(ele, e) {
    var key;
    if (window.event) { key = window.event.keyCode; }
    else { key = e.which; }
    if (key == 13 || key == 9) {
        var btn = TF.X.GetElementById(buttonName);
        if (btn != null) { btn.click(); }
        e.stopPropagation && e.stopPropagation();
        e.preventDefault && e.preventDefault();
        e.cancelBubble = true;
        e.returnValue = false;
        e.keyCode = 0;
    }
};



// Tino Zijdel - crisp@xs4all.nl This little snippet fixes the problem that the onload attribute on 
// the body-element will overwrite previous attached events on the window object for the onload event.
if (!window.addEventListener) {
    document.onreadystatechange = function() {
        if (window.onload && window.onload !== TFHandleEvent) {
            _AddEvent(window, 'load', window.onload);
            window.onload = TFHandleEvent;
        }
    };
}

// Here are my functions for adding the DOMContentLoaded event to browsers other
// than Mozilla.
// Function to process the DOMContentLoaded events array.
function DOMContentLoadedInit() {
    // quit if this function has already been called
    if (window._DOMContentLoadedInitDone) { return; }
    window._DOMContentLoadedInitDone = true;
    // iterates through array of registered functions 
    for (var i = 0; i < window._onDOMLoadEvents.length; i++) {
        var func = window._onDOMLoadEvents[i];
        func();
    }
}

function DOMContentLoadedScheduler() {
    // quit if the init function has already been called
    if (window._DOMContentLoadedInitDone) { return true; }
    // First, check for Safari or KHTML.
    // Second, check for IE.
    //if DOM methods are supported, and the body element exists
    //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
    //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
    if (/KHTML|WebKit/i.test(navigator.userAgent)) {
        if (/loaded|complete/.test(document.readyState)) {
            DOMContentLoadedInit();
        } else {
            // Not ready yet, wait a little more.
            setTimeout(DOMContentLoadedScheduler, 250);
        }
    } else if (_gE("__ie_onload")) {
        return true;
    }

    // Check for custom developer provided function.
    if (typeof DOMContentLoadedCustom === "function") {
        if (typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null)) {
            // Call custom function.
            if (DOMContentLoadedCustom()) {
                DOMContentLoadedInit();
            } else {
                // Not ready yet, wait a little more.
                setTimeout(DOMContentLoadedScheduler, 250);
            }
        }
    }
    return true;
}

// If addEventListener supports the DOMContentLoaded event.
if (document.addEventListener) { document.addEventListener("DOMContentLoaded", DOMContentLoadedInit, false); }
// Schedule to run the init function.
window.setTimeout(DOMContentLoadedScheduler, 250);
// Just in case window.onload happens first, add it there too.
_AddEvent(window, "load", DOMContentLoadedInit);


/* for Internet Explorer */
/*@cc_on
@if (@_win32 || @_win64)
document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
var mScript = document.getElementById("__ie_onload");
mScript.onreadystatechange = function() {
    if (this.readyState == "complete") {
        DOMContentLoadedInit(); // call the onload handler
    }
};
@end
@*/

////document.evaluate for IE
//if (_TF.is.ie) {
//    window._content = window; var r; if (window.dialogArguments && window.dialogArguments.external) { r = window.dialogArguments.external; } else if (window.external) { r = window.external; } var s = new _XPathExceptionHandler(); function _XPathExceptionHandler() { this.INVALID_EXPRESSION_ERR = 51; this.TYPE_ERR = 52; this.NOT_IMPLEMENTED_ERR = -1; this.RUNTIME_ERR = -2; this.ThrowNotImplemented = function(a) { ThrowError(this.NOT_IMPLEMENTED_ERR, "This functionality is not implemented.", a); }; this.ThrowInvalidExpression = function(a) { ThrowError(this.INVALID_EXPRESSION_ERR, "Invalid expression", a); }; this.ThrowType = function(a) { ThrowError(this.TYPE_ERR, "Type error", a); }; this.Throw = function(a) { ThrowError(this.RUNTIME_ERR, "Run-time error", a); }; function ThrowError(b, c, a) { var t = new Error(b, "DOM-L3-XPath : " + c + (a ? ", \"" + a + "\"" : "")); t.b = b; t.name = "XPathException"; throw t; } } var u = new _DOMExceptionHandler(); function _DOMExceptionHandler() { this.ThrowInvalidState = function(a) { ThrowError(13, "The state of the object is no longer valid", a); }; function ThrowError(b, c, a) { var t = new Error(b, "DOM : " + c + (a ? ", \"" + a + "\"" : "")); t.b = b; t.name = "DOMException"; throw t; } } document.createExpression = function(d, e) { return new XPathExpression(d, e); }; document.createNSResolver = function(f) { return new XPathNSResolver(f); }; document.evaluate = function(d, g, e, h, j) { return document.createExpression(d, e).evaluate(g, h, j); }; function XPathExpression(d, e) { this.expressionString = d; this.e = e; this.evaluate = function(g, h, j) { return (j && j.constructor == XPathResult ? j.initialize(this, g, e, h) : new XPathResult(this, g, e, h)); }; this.toString = function() { return "[XPathExpression]"; }; } function XPathNSResolver(k) { this.k = k; this.lookupNamespaceURI = function(l) { s.ThrowNotImplemented(); return null; }; this.toString = function() { return "[XPathNSResolver]"; }; } XPathResult.ANY_TYPE = 0; XPathResult.NUMBER_TYPE = 1; XPathResult.STRING_TYPE = 2; XPathResult.BOOLEAN_TYPE = 3; XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4; XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5; XPathResult.UNORDERED_SNAPSHOT_TYPE = 6; XPathResult.ORDERED_SNAPSHOT_TYPE = 7; XPathResult.ANY_UNORDERED_NODE_TYPE = 8; XPathResult.FIRST_ORDERED_NODE_TYPE = 9; function XPathResult(d, g, e, h) {
//        this.initialize = function(d, g, e, h) { this._domResult = null; this._expression = d; this._contextNode = g; this._resolver = e; if (h) { this.resultType = h; this._isIterator = (h == XPathResult.UNORDERED_NODE_ITERATOR_TYPE || h == XPathResult.ORDERED_NODE_ITERATOR_TYPE || h == XPathResult.ANY_TYPE); this._isSnapshot = (h == XPathResult.UNORDERED_SNAPSHOT_TYPE || h == XPathResult.ORDERED_SNAPSHOT_TYPE); this._isNodeSet = h > XPathResult.BOOLEAN_TYPE; } else { this.resultType = XPathResult.ANY_TYPE; this._isIterator = true; this._isSnapshot = false; this._isNodeSet = true; } return this; }; this.initialize(d, g, e, h); this.getInvalidIteratorState = function() { return documentChangeDetected() || !this._isIterator; }; this.getSnapshotLength = function() { if (!this._isSnapshot) { s.ThrowType("Snapshot is not an expected result type"); } activateResult(this); return this._domResult._b; }; this.iterateNext = function() { if (!this._isIterator) { s.ThrowType("Iterator is not an expected result type"); } activateResult(this); if (documentChangeDetected()) { u.ThrowInvalidState("iterateNext"); } return getNextNode(this); }; this.snapshotItem = function(m) { if (!this._isSnapshot) { s.ThrowType("Snapshot is not an expected result type"); } return getItemNode(this, m); }; this.toString = function() { return "[XPathResult]"; }; this.getStringValue = function() { if (this.resultType != XPathResult.STRING_TYPE) { s.ThrowType("The expression can not be converted to return String"); } return getNodeText(this); }; this.getNumberValue = function() { if (this.resultType != XPathResult.NUMBER_TYPE) { s.ThrowType("The expression can not be converted to return Number"); } var v = parseInt(getNodeText(this)); if (isNaN(v)) { s.ThrowType("The result can not be converted to Number"); } return v; }; this.getBooleanValue = function() {
//            if (this.resultType != XPathResult.BOOLEAN_TYPE) { s.ThrowType("The expression can not be converted to return Boolean"); } var 
//w = getNodeText(this); bool = (w ? w.toLowerCase() : null); if (bool == "false" || bool == "true") { return bool; } s.ThrowType("The result can not be converted to Boolean");
//        }; this.getSingleNodeValue = function() { if (this.resultType != XPathResult.ANY_UNORDERED_NODE_TYPE && this.resultType != XPathResult.FIRST_ORDERED_NODE_TYPE) { s.ThrowType("The expression can not be converted to return single Node value"); } return getSingleNode(this); }; function documentChangeDetected() { return document._XPathMsxmlDocumentHelper.documentChangeDetected(); }; function getNodeText(j) { activateResult(j); return j._textResult; }; function findNode(j, n) { switch (n.nodeType) { case 1: var x = n.attributes.getNamedItem("id"); if (x) { return _gE(x.value); } s.Throw("unable to locate element in XML tree"); case 2: var x = n.selectSingleNode("..").attributes.getNamedItem("id"); if (x) { var k = _gE(x.w); if (k) { return k.attributes.getNamedItem(n.nodeName); } } s.Throw("unable to locate attribute in XML tree"); case 3: var x = n.selectSingleNode("..").attributes.getNamedItem("id"); if (x) { var k = _gE(x.value); if (k) { for (child in k.childNodes) { if (child.nodeType == 3 && child.nodeValue == n.nodeValue) { return child; } } } } s.Throw("unable to locate text in XML tree"); } s.Throw("unknown node type"); } function activateResult(j) { if (!j._domResult) { try { var d = j._expression.expressionString; if (j._contextNode != document && d.indexOf("//") != 0) { d = "//*[@id = '" + j._contextNode.x + "']" + (d.indexOf("/") == 0 ? "" : "/") + d; } if (j._isNodeSet) { j._domResult = document._XPathMsxmlDocumentHelper.getDom().selectNodes(d); } else { j._domResult = true; j._textResult = document._XPathMsxmlDocumentHelper.getTextResult(d); } } catch (t) { alert(t.c); s.ThrowInvalidExpression(t.c); } } } function getSingleNode(j) { var k = getItemNode(j, 0); j._domResult = null; return k; } function getItemNode(j, m) { activateResult(j); var n = j._domResult.item(m); return (n ? findNode(j, n) : null); } function getNextNode(j) { var n = j._domResult.nextNode; if (n) { return findNode(j, n); } j._domResult = null; return null; } 
//    } document.reloadDom = function() { document._XPathMsxmlDocumentHelper.reset(); }; document._XPathMsxmlDocumentHelper = new _XPathMsxmlDocumentHelper(); function _XPathMsxmlDocumentHelper() { this.getDom = function() { activateDom(this); return this.p; }; this.getXml = function() { activateDom(this); return this.p.xml; }; this.getTextResult = function(d) { d = d.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "\""); var y = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:output method=\"text\"/><xsl:template match=\"*\"><xsl:value-of select=\"" + d + "\"/>" + "</xsl:template></xsl:stylesheet>"; var z = new ActiveXObject("Msxml2.DOMDocument"); z.loadXML(y); try { var j = this.getDom().transformNode(z); } catch (t) { alert("Error: " + t.c); } return j; }; this.reset = function() { this.p = null; }; function onPropertyChangeEventHandler() { document._propertyChangeDetected = true; } this.documentChangeDetected = function() { return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all._b || document._propertyChangeDetected); }; function activateDom(o) { if (!o.p) { var p = new ActiveXObject("Msxml2.DOMDocument"); p.async = false; p.resolveExternals = false; loadDocument(p, o); o.p = p; o._currentElementCount = document.all._b; document._propertyChangeDetected = false; } else { if (o.documentChangeDetected()) { var p = o.p; p.load(""); loadDocument(p, o); o._currentElementCount = document.all._b; document._propertyChangeDetected = false; } } } function loadDocument(p, o) { return loadNode(p, p, document.body, o); } function loadNode(p, q, k, o) { if (k.nodeType == 3) { q.appendChild(p.createTextNode(k.nodeValue)); } else { var _a = p.createElement(k.nodeName.toLowerCase()); if (!k.x) { k.x = k.uniqueID; } q.appendChild(_a); loadAttributes(p, _a, k); var _b = k.childNodes._b; for (var i = 0; i < _b; i++) { loadNode(p, _a, k.childNodes[i], o); } k.attachEvent("onpropertychange", onPropertyChangeEventHandler); } } function loadAttributes(p, q, k) { for (var i = 0; i < k.attributes._b; i++) { var _c = k.attributes[i]; var _d = _c.nodeValue; if (_d && _c.specified) { var _e = p.createAttribute(_c.nodeName); _e.value = _d; q.setAttributeNode(_e); } } } } 
//} else { document.reloadDom = function() { }; XPathResult.prototype.getStringValue = function() { return this.stringValue; }; XPathResult.prototype.getNumberValue = function() { return this.numberValue; }; XPathResult.prototype.getBooleanValue = function() { return this.booleanValue; }; XPathResult.prototype.getSingleNodeValue = function() { return this.singleNodeValue; }; XPathResult.prototype.getInvalidIteratorState = function() { return this.invalidIteratorState; }; XPathResult.prototype.getSnapshotLength = function() { return this.snapshotLength; }; XPathResult.prototype.getResultType = function() { return this.resultType; }; }
